from __future__ import division
from operator import itemgetter, attrgetter
from struct import *
import gc
import math
import os
import pylab
import random
import sys
import time

print "Hello WSDM2014"
print "STOP DOING THIS, I have found that I have already DONE this before."
exit(1)

inputFileList = []
# on moa:
# [1,10000]
inputFileName1 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xaa"
# [10001,20000]
inputFileName2 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xab"
# [20000,30000]
inputFileName3 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xac"
# [30001,40000]
inputFileName4 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xad"
# [40001,50000]
inputFileName5 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xae"
# [50001,54361]
inputFileName6 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xaf_Part1"
# [54362,60000]
inputFileName7 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xaf_Part2"
# [60001,64394]
inputFileName8 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xag_Part1"
# [64395,70000]
inputFileName9 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xag_Part2"
# [70001,74644]
inputFileName10 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xah_Part1"
# [74645,80000]
inputFileName11 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xah_Part2"
# [80001,84532]
inputFileName12 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xai_Part1"
# [84533,90000]
inputFileName13 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xai_Part2"
# [90001,94242]
inputFileName14 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xaj_Part1"
# [94243,95000]
inputFileName15 = "/home/diaosi/workspace/web-search-engine-wei-2014-April/results/rawResults_100%_TOP1000_AND_20140101Night_xaj_Part2"

inputFileList.append(inputFileName1)
inputFileList.append(inputFileName2)
inputFileList.append(inputFileName3)
inputFileList.append(inputFileName4)
inputFileList.append(inputFileName5)
inputFileList.append(inputFileName6)
inputFileList.append(inputFileName7)
inputFileList.append(inputFileName8)
inputFileList.append(inputFileName9)
inputFileList.append(inputFileName10)
inputFileList.append(inputFileName11)
inputFileList.append(inputFileName12)
inputFileList.append(inputFileName13)
inputFileList.append(inputFileName14)
inputFileList.append(inputFileName15)

numOfTop10DocumentResultLines = 0
for currentFileName in inputFileList:
    currentFileHandler = open(currentFileName,"r")
    print "processing",currentFileName
    currentLine = currentFileHandler.readline()
    while currentLine:
        currentLineElements = currentLine.strip().split(" ")
        if currentLineElements[-1].startswith("GX") and int(currentLineElements[0]) <= 10:
            # print currentLine.strip()
            numOfTop10DocumentResultLines += 1
        currentLine = currentFileHandler.readline()
    print "numOfPostings:",numOfTop10DocumentResultLines
print "Ends."
